package flc.ast.fragment;

import android.Manifest;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.R;
import flc.ast.activity.FileScanQrActivity;
import flc.ast.activity.FileTransferActivity;
import flc.ast.activity.SelToolVideoActivity;
import flc.ast.activity.SelVideoActivity;
import flc.ast.databinding.FragmentFormatBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StkPermissionHelper;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link FormatFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class FormatFragment extends BaseNoModelFragment<FragmentFormatBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_format;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivUploadVideo.setOnClickListener(this);
        mDataBinding.rlGifMake.setOnClickListener(this);
        mDataBinding.rlVideoGif.setOnClickListener(this);
        mDataBinding.rlFileTransfer.setOnClickListener(this);
        mDataBinding.rlFileReceive.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivUploadVideo://上传视频
                startActivity(SelVideoActivity.class);
                break;
            case R.id.rlGifMake://gif制作
                SelToolVideoActivity.type = 0;
                startActivity(SelToolVideoActivity.class);
                break;
            case R.id.rlVideoGif://视频转gif
                SelToolVideoActivity.type = 1;
                startActivity(SelToolVideoActivity.class);
                break;
            case R.id.rlFileTransfer://传送文件
                getTransferPermission();
                break;
            case R.id.rlFileReceive://接收文件
                getReceivePermission();
                break;
        }
    }

    @Override
    protected void initData() {

    }

    private void getTransferPermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_ALL_MEDIA)
                .reqPermissionDesc(getString(R.string.get_transfer_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        startActivity(FileTransferActivity.class);
                    }

                    @Override
                    public void onDenied(boolean needGoSettings) {
                        ToastUtils.showShort(getString(R.string.no_permission));
                    }
                }).request();
    }

    private void getReceivePermission() {
        StkPermissionHelper.permission(StkPermissionHelper.Permission.ACCESS_ALL_MEDIA, Manifest.permission.CAMERA)
                .reqPermissionDesc(getString(R.string.get_receive_permission))
                .callback(new StkPermissionHelper.ACallback() {
                    @Override
                    public void onGranted() {
                        startActivity(FileScanQrActivity.class);
                    }

                    @Override
                    public void onDenied(boolean needGoSettings) {
                        ToastUtils.showShort(getString(R.string.no_permission));
                    }
                }).request();
    }

}